package com.mingyizhudao.app.view.home.adapter;

import java.util.ArrayList;
import java.util.List;

import com.mingyizhudao.app.R;
import com.mingyizhudao.app.view.home.bean.DisNavsEntity;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class DeptGridListAdapter extends BaseAdapter {

	private Context mContext;
	private List<DisNavsEntity> disNavs = new ArrayList<DisNavsEntity>();
	private LayoutInflater inflater;

	public DeptGridListAdapter(Context context) {
		this.mContext = context;
		this.inflater = LayoutInflater.from(mContext);
	}

	@Override
	public int getCount() {
		return disNavs != null ? disNavs.size() : 0;
	}

	public void setData(List<DisNavsEntity> disNavs) {

		this.disNavs = disNavs;
	}

	@Override
	public Object getItem(int arg0) {
		return disNavs.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.gv_item_homedept, parent,false);
			holder = new ViewHolder();
			holder.iv_dpet = (ImageView) convertView.findViewById(R.id.iv_dpet);
			holder.tv_dept = (TextView) convertView.findViewById(R.id.tv_dept);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.tv_dept.setText(disNavs.get(position).getName());
		
		if ("外科".equals(disNavs.get(position).getName())) {
			holder.iv_dpet.setImageResource(R.drawable.home_waike);
		}
		if ("骨科".equals(disNavs.get(position).getName())) {
			holder.iv_dpet.setImageResource(R.drawable.home_guke);
		}
		if ("妇产科".equals(disNavs.get(position).getName())) {
			holder.iv_dpet.setImageResource(R.drawable.home_fuchan);
		}
		if ("小儿外科".equals(disNavs.get(position).getName())) {
			holder.iv_dpet.setImageResource(R.drawable.home_xiaoer);
		}
		if ("五官科".equals(disNavs.get(position).getName())) {
			holder.iv_dpet.setImageResource(R.drawable.home_wuguan);
		}
		if ("内科".equals(disNavs.get(position).getName())) {
			holder.iv_dpet.setImageResource(R.drawable.home_neike);
		}
		
		return convertView;
	}

	public final class ViewHolder {
		public ImageView iv_dpet = null;
		public TextView tv_dept = null;
	}

}
